package dy.com.收发并行.Server;

import dy.com.收发并行.constants.TCPConstants;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.nio.ByteBuffer;

public class Server {
    public static void main(String[] args) throws IOException {
        //开启TCP监听
        TCPServer tcpServer = new TCPServer(TCPConstants.TCP_PORT_SERVER);
        try {
            tcpServer.start();
        } catch (IOException e) {
            System.out.println("tcp监听开启失败");
            return;
        }

        //开启udp监听
        UDPServerProvider.start(TCPConstants.TCP_PORT_SERVER);

        //服务器获得键盘输入，给客户端传输
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while(!(str = bufferedReader.readLine()).equals("00bye00")){

            tcpServer.broadcast(str);
        }
        UDPServerProvider.stop();
        tcpServer.stop();
    }
}
